﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTCash.Logger;
using DTCash.Logger.DTO;
using DTCash.Redis;
using Uranus.Service.ForwardProductService;

namespace Uranus.Service
{
    public class ForwardProduct : BaseData
    {
        private static ForwardProduct forwardProduct;
        private ForwardProduct()
        {

        }

        public static ForwardProduct GetForwardProduct()
        {
            if (forwardProduct == null)
            {
                forwardProduct = new ForwardProduct();
            }
            return forwardProduct;
        }

        /// <summary>
        /// 根据条件查询借款人信息
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns></returns>
        public UserInfoResponse GetLoanerUserInfo(UserInfoRequest request)
        {
            ForwardProductService.ForwardProductServiceClient userServiceClick = new ForwardProductServiceClient();
            try
            {
                CacheKey cacheKey = CacheItem.InitByIdentity(request.Info.UserID + "", "GetLoanerUserInfo").User.Info;
                Func<UserInfoResponse> method = delegate
                {
                    UserInfoResponse userPropertyRes = userServiceClick.GetLoanerUserInfo(request);
                    return userPropertyRes;
                };
                return base.GetData<UserInfoResponse>(method, cacheKey);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogEnum.Error, "Uranus.Service.ForwardProduct.GetLoanerUserInfo 出现异常", ex.Message, request.Info.UserID);
                return null;
            }
            finally
            {
                userServiceClick.Close();
            }
        }
    }
}
